package br.ufrj.dcc.smarthotel.activities;

import java.util.Enumeration;
import java.util.Hashtable;

import br.ufrj.dcc.smarthotel.entities.Session;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class AppActivity extends Activity {
	private static Session sessionInfo;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    
    public void showQuickMessage(int stringId) {
    	Toast.makeText(getApplicationContext(), getString(stringId), Toast.LENGTH_LONG).show();
    }
    
    public void startActivity(Class<?> activityClass) {
    	Intent intent = new Intent(this, activityClass);
    	this.startActivity(intent);
    }
    
    public void startActivity(Class<?> activityClass, Hashtable<String, String> params) {
    	Intent intent = new Intent(this, activityClass);
    	Bundle bundle = new Bundle();
    	
    	Enumeration<String> e = params.keys();
    	
    	while(e.hasMoreElements()) {
    		String key = e.nextElement();
    		
    		bundle.putString(key, params.get(key));
    	}
    	
    	intent.putExtras(bundle);
    	
    	this.startActivity(intent);
    }
    
    public void startActivity(Class<?> activityClass, Hashtable<String, String> params, int requestCode) {
    	Intent intent = new Intent(this, activityClass);
    	Bundle bundle = new Bundle();
    	
    	Enumeration<String> e = params.keys();
    	
    	while(e.hasMoreElements()) {
    		String key = e.nextElement();
    		
    		bundle.putString(key, params.get(key));
    	}
    	
    	intent.putExtras(bundle);
    	
    	this.startActivityForResult(intent, requestCode);
	}
    
    public static void setSessionInfo(Session newSessionInfo) {
    	sessionInfo = newSessionInfo;
    }
    
    public static Session getSessionInfo() {
    	return sessionInfo;
    }
}
